package com.longdaji.decoration.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.longdaji.decoration.R;
import com.longdaji.decoration.bean.Profit;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Kanade on 2018/4/7 0007.
 */

public class ProfitAdapter extends RecyclerView.Adapter<ProfitAdapter.ProfitHolder> {
    private List<Profit> mProfitList = new ArrayList<>();
    private Context mContext;

    public ProfitAdapter(List<Profit> profitList) {
        this.mProfitList = profitList;
    }

    class ProfitHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_trade_dormitory)
        TextView tvTradeDormitory;
        @BindView(R.id.tv_trade_number)
        TextView tvTradeNumber;
        @BindView(R.id.tv_trade_time)
        TextView tvTradeTime;

        public ProfitHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    @Override
    public ProfitHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_profit, parent, false);
        ProfitHolder holder = new ProfitHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ProfitHolder holder, int position) {
        Profit profit = mProfitList.get(position);
        holder.tvTradeDormitory.setText(profit.getTradeDormitory());
        holder.tvTradeNumber.setText("交易" + String.valueOf(profit.getTradeNumber()) + "笔");
        holder.tvTradeTime.setText(profit.getTradeTime());
    }

    @Override
    public int getItemCount() {
        return mProfitList.size();
    }

    public void setData(List<Profit> list) {
        mProfitList.clear();
        mProfitList.addAll(list);
        notifyDataSetChanged();
    }
}
